<template>
  <div class="container">
    <leftcont></leftcont>
    <div class="righCont">
      <topcont></topcont>
      <div class="content">
        <div class="payTable">
          <div class="trendTop">需求审核({{ total }})</div>
          <div class="tableCont">
            <el-table :data="tableData" style="width: 100%">
              <el-table-column
                prop="project_name"
                show-overflow-tooltip
                label="需求名称"
              >
              </el-table-column>
              <el-table-column
                show-overflow-tooltip
                prop="project_budget"
                label="需求价格"
              >
              </el-table-column>
              <el-table-column label="项目周期">
                <template #default="scope">
                  {{ scope.row.project_cycle }}个月
                </template>
              </el-table-column>
              <el-table-column label="经验要求">
                <template #default="scope">
                  {{ scope.row.jdjy }}年以上
                </template>
              </el-table-column>
              <el-table-column prop="jdqt" label="接单群体"> </el-table-column>
              <el-table-column width="180" prop="create_time" label="发布时间">
              </el-table-column>
              <el-table-column label="操作" width="200">
                <template #default="scope">
                  <div class="ctrolBtn">
                    <div class="text_btn greenBtn" @click="toDetail(scope.row)">
                      详情
                    </div>
                  </div>
                </template>
              </el-table-column>
            </el-table>
            <div class="pageCont">
              <el-pagination
                background
                layout="prev, pager, next"
                :page-size="per_page"
                :current-page="page"
                @current-change="pageFn"
                :total="total"
              >
              </el-pagination>
            </div>
          </div>
        </div>
      </div>
    </div>
    <el-dialog v-model="dialogVisible" width="800">
      <el-descriptions title="项目详情">
        <el-descriptions-item label="项目名称">{{
          activeItem.project_name
        }}</el-descriptions-item>

        <el-descriptions-item label="项目价格">{{
          activeItem.project_budget
        }}</el-descriptions-item>
        <el-descriptions-item label="项目周期"
          >{{ activeItem.project_cycle }} 个月</el-descriptions-item
        >
        <el-descriptions-item label="经验要求"
          >{{ activeItem.jdjy }}年以上</el-descriptions-item
        >
        <el-descriptions-item label="办公要求">{{
          activeItem.bgyq
        }}</el-descriptions-item>
        <el-descriptions-item label="接单群体">{{
          activeItem.jdqt
        }}</el-descriptions-item>
        <el-descriptions-item label="发布时间">{{
          activeItem.create_time
        }}</el-descriptions-item>
        <el-descriptions-item label="截止时间">{{
          activeItem.end_time
        }}</el-descriptions-item>
        <el-descriptions-item label="企业名称"
          >{{ activeItem.enterprise_name
          }}<span style="color: #f56c6c" v-if="activeItem.is_virtually == 2"
            >*</span
          ></el-descriptions-item
        >
      </el-descriptions>
      <el-descriptions title="需求说明">
        <el-descriptions-item>{{
          activeItem.project_describe
        }}</el-descriptions-item>
      </el-descriptions>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="checkStatus(activeItem, 3)">驳回</el-button>
          <el-button type="primary" @click="checkStatus(activeItem, 2)">
            通过
          </el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script>
import leftcont from "@/components/leftCont.vue";
import topcont from "@/components/topCont.vue";
import btn from "@/components/public/btn.vue";
import { projectExamineRecord, projectExamineSave } from "@/http/api";
import { ElMessage, ElMessageBox } from "element-plus";

export default {
  components: { leftcont, topcont, btn },
  data() {
    return {
      dialogVisible: false,
      serchVal: "",
      tableData: [{}],
      page: 1,
      per_page: 5,
      total: 0,
      activeItem: {},
    };
  },
  props: {},
  methods: {
    toDetail(item) {
      this.activeItem = item;
      this.dialogVisible = true;
    },
    checkStatus(item, type) {
      if (type == 2) {
        ElMessageBox.confirm(`确认通过此需求审核?`, "审核提示", {
          confirmButtonText: "确认",
          cancelButtonText: "取消",
          type: "warning",
        }).then(() => {
          let data = {
            project_demand_id: item.project_demand_id,
            examine_status: 2,
          };
          projectExamineSave(data).then((res) => {
            if (res.data.code == 1) {
              ElMessage({
                type: "success",
                message: "审核已通过",
              });
              this.getData();
              this.dialogVisible = false;
            } else {
              ElMessage(res.data.msg);
            }
          });
        });
      } else {
        ElMessageBox.prompt(`请输入驳回理由`, "审核提示", {
          confirmButtonText: "确认",
          cancelButtonText: "取消",
          type: "warning",
        }).then((val) => {
          console.log(val);
          if (!val.value) {
            ElMessage("请输入驳回理由");
            return false;
          }
          let data = {
            reason: val.value,
            project_demand_id: item.project_demand_id,
            examine_status: 3,
          };
          projectExamineSave(data).then((res) => {
            if (res.data.code == 1) {
              ElMessage({
                type: "success",
                message: "审核已驳回",
              });
              this.getData();
              this.dialogVisible = false;
            } else {
              ElMessage(res.data.msg);
            }
          });
        });
      }
    },
    pageFn(index) {
      this.page = index;
      this.getData();
    },
    serchFn() {
      this.page = 1;
      this.total = 0;
      this.getData();
    },
    getData() {
      var data = {
        page: this.page,
        per_page: this.per_page,
      };
      projectExamineRecord(data)
        .then((res) => {
          if (res.data.code == 1) {
            this.tableData = res.data.data.data; //把最新的数组赋值给tableData
            this.total = res.data.data.total;
          } else {
            ElMessage(res.data.msg);
          }
        })
        .catch((err) => {
          ElMessage.error("服务器请求超时");
        });
    },
  },
  mounted() {},
  created() {
    this.getData();
  },
};
</script>

<style scoped lang="less">
.container {
  width: 100%;
  display: flex;
  height: 100vh;
  overflow: hidden;
  .righCont {
    display: flex;
    flex-direction: column;
    flex: 1;
    margin-left: 15px;
    height: 100%;
    width: 10px;
    background-color: #f4f8ff;
    .content {
      padding: 20px;
      box-sizing: border-box;
      width: 100%;
      flex: 1;
      .payTable {
        width: 100%;
        height: 100%;
        background-color: #fff;
        padding: 15px;
        border-radius: 5px;
        overflow: auto;
        box-sizing: border-box;
        .trendTop {
          font-weight: bold;
          font-size: 16px;
          cursor: pointer;
        }
        .tableCont {
          width: 100%;
          margin-top: 15px;
          .redBtn {
            color: #f56c6c;
          }
          .blueBtn {
            color: #96a1fe;
          }
          .greenBtn {
            color: #85ce61;
          }
          .blackBtn {
            color: #666;
          }
          .tableSerchCont {
            width: 100%;
            display: flex;
            justify-content: flex-end;
            margin-bottom: 10px;
            .serchItem {
              width: 150px;
              margin-left: 10px;
            }
            .headBtn {
              margin-left: 10px;
            }
          }
          .ctrolBtn {
            display: flex;
            .text_btn {
              margin: 0 5px;
              cursor: pointer;
              font-size: 14px;
            }
          }
          .pageCont {
            padding: 30px 0;
            display: flex;
            justify-content: center;
          }
        }
      }
    }
  }
}
</style>
